package com.ruoyi.web.controller.nongjt;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.nongjt.domain.NjtInspectionRecord;
import com.ruoyi.nongjt.service.NjtInspectionRecordService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author L
 * @version 1.0
 * @date 2025/9/26 13:38
 * @see http://baidu.com
 */
@RestController
@RequestMapping("/nongjt/inspection")
public class NjtInspectionRecordController extends BaseController {

    @Autowired
    private NjtInspectionRecordService inspectionRecordService;

    /**
     * 查询检查记录列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:inspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjtInspectionRecord inspectionRecord) {
        startPage();
        List<NjtInspectionRecord> list = inspectionRecordService.selectNjtInspectionRecordList(inspectionRecord);
        return getDataTable(list);
    }

    /**
     * 导出检查记录列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:inspection:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjtInspectionRecord inspectionRecord) {
        List<NjtInspectionRecord> list = inspectionRecordService.selectNjtInspectionRecordList(inspectionRecord);
        ExcelUtil<NjtInspectionRecord> util = new ExcelUtil<>(NjtInspectionRecord.class);
        util.exportExcel(response, list, "检查记录数据");
    }

    /**
     * 获取检查记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:inspection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(inspectionRecordService.selectNjtInspectionRecordById(id));
    }

    /**
     * 新增检查记录
     */
    @PreAuthorize("@ss.hasPermi('nongjt:inspection:add')")
    @PostMapping
    public AjaxResult add(@RequestBody NjtInspectionRecord inspectionRecord) {
        return toAjax(inspectionRecordService.insertNjtInspectionRecord(inspectionRecord));
    }

    /**
     * 修改检查记录
     */
    @PreAuthorize("@ss.hasPermi('nongjt:inspection:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody NjtInspectionRecord inspectionRecord) {
        return toAjax(inspectionRecordService.updateNjtInspectionRecord(inspectionRecord));
    }

    /**
     * 删除检查记录
     */
    @PreAuthorize("@ss.hasPermi('nongjt:inspection:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(inspectionRecordService.deleteNjtInspectionRecordByIds(ids));
    }
}